package at.ac.univie.ke.neuranetwork;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class FileHandler implements Constants{
	
	private String basePathString;
	
	//constructors
	private FileHandler(){}
	public FileHandler(String directory){
		setBasePathString(directory);
	}
	
	
	public List<String> getConfigFiles(){
		File folder = new File( getBasePathString() );
		File[] listOfFiles = folder.listFiles();
		
		List<String> fileList = new ArrayList<String>();

		for (File file : listOfFiles) {
		    if (file.isFile()) {
		    	if(file.getName().endsWith(NNET_FILE_EXTENSION))
		    		fileList.add(file.getName());
		    }
		}
		
		return fileList;
	}
	
	public double[] getCustomImage(int number){
		
		File file = new File(getBasePathString() + "/" 
				 + Integer.toString(number) + ".txt");
		double[] imageArray = new double[784];
		
		try {
			Scanner scan = new Scanner(file);
			int i = 0;
			while(scan.hasNextDouble())
		    {	
				imageArray[i] = scan.nextDouble();
				i++;
		    }
	
		    } catch (FileNotFoundException e1) {
		            e1.printStackTrace();
		    }
		
		
		return imageArray;
	}
	
	public String getBasePathString() {
		return basePathString;
	}
	
	public void setBasePathString(String basePathString) {
		this.basePathString = basePathString;
	}
	

	
}
